angular.module('ui.textInput',[]).directive('uiButton', function ($compileProvider) {
	return{
		restrict:'AE',
		scope:{
			water:'@'
		},
		transclude : true,
		replace:true,
		templateUrl:'{{water}}.html',
		compile: function(tElem, tAttrs){
			console.log(': pre compile => ' + tElem.html());
		},
		link: function(scope, element, attr) {
			console.log(': pre link => ' + element.html());
		}
	}
});

angular.module('ui.textInput', [], function($compileProvider) {
    // configure new 'compile' directive by passing a directive
    // factory function. The factory function injects the '$compile'
    $compileProvider.directive('compile', function($compile) {
      // directive factory creates a link function
      return function(scope, element, attrs) {
    	  
    	  restrict:'AE',
    	  scope.$watch(
          function(scope) {
             // watch the 'compile' expression for changes
            return scope.$eval(attrs.compile);
          },
          function(value) {
    
            // when the 'compile' expression changes
            // assign it into the current DOM
        	  if(attrs.type=='string')
        		  value='<input type="text" class="form-control .col-lg-2" placeholder="请输入" ng-model="param.'+attrs.name+'" >';
        	  else if(attrs.type=='date'){
        		  value='<div class="input-group w-md"  ng-controller="DatepickerDemoCtrl">';
        		  value+='<input type="text" class="form-control" datepicker-popup="{{format}}" ng-model="param.'+attrs.name+'" is-open="opened" datepicker-options="dateOptions" ng-required="true" close-text="Close" />';
        		  value+='<span class="input-group-btn">';
        		  value+='<button type="button" class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>'
        		  value+=' </span>';
        		  value+='</div>';
                
        	  }
            element.html(value);

            // compile the new DOM and link it to the current
            // scope.
            // NOTE: we only compile .childNodes so that
            // we don't get into infinite loop compiling ourselves
            $compile(element.contents())(scope);
          }
        );
      };
    });
  });